package cjvision.boot.base.ai.utils.baidu;

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 *
 * @FileName: LoginSimulator
 * @Author: XY //作者
 * @Date: 2024-07-24 09:39  //完成日期
 * @Description:   // 描述
 * @Version: v0.0.1 // 版本信息
 * @Function List: // 主要函数及其功能
 * @Others: // 其它内容的说明
 * @History: // 历史修改记录
 */
public class LoginSimulator
{

    public static void main(String[] args)
    {
        int intIime = 800;
        String pwd = "dg110929";
         // 大号组
//         String[] daHao = {
                 "a452746100",
                 "b452746100",
                 "c452746100",
                 "d452746100",
                 "e452746100",
                 "f452746100",
                 "g452746100",
                 "h452746100",
                 "i452746100",
                 "j452746100",
                 "k452746100",
                 "l452746100",
                 "m452746100",
                 "n452746100",
                 "o452746100",
                 "p452746100",
                 "q452746100",
                 "r452746100",
                 "s452746100",
                 "t452746100",
                 "u452746100",
                 "v452746100",
                 "w452746100",
                 "x452746100",
                 "y452746100",
                 "z452746100",
//         };
//         for (int i = 0; i <= daHao.length; i++) {
//             try {
////                 System.err.println(daHao[i] + ',' + pwd);
//                  System.err.println(getSid(daHao[i], pwd) + ',');
//                 Thread.sleep(intIime);
//             } catch (InterruptedException e) {
//                 e.printStackTrace();
//             }
//         }

        String comount = "gxst";
        String username = "";
        // 小号组
//        int maxNum = 100;
//        for (int i = 1; i <= maxNum; i++) {
//            try {
//                if (i < 10) {
//                    username = comount + "00" + i;
//                } else if (i < 100 ) {
//                    username = comount + "0" + i;
//                } else {
//                    username = comount + i;
//                }
////                System.err.println(username + ',' + pwd);
//                 System.err.println(getSid(username, pwd) + ',');
//                Thread.sleep(intIime);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
//
        // 仓库组
//       int maxNum = 550;
//       for (int i = 101; i <= maxNum; i++) {
//           try {
//               username = comount + i;
////               System.err.println(username + ',' + pwd);
//               System.err.println(getSid(username, pwd) + ',');
//               Thread.sleep(intIime);
//           } catch (InterruptedException e) {
//               e.printStackTrace();
//           }
//       }
    }

    public static String getSid(String account, String password)
    {
        String loginUrl = "https://www.5iwapgame.com/home/loginValidate.go";
        HttpURLConnection connection = null;
        String sid = "";
        try
        {
            // 创建URL对象
            URL url = new URL(loginUrl);
            // 打开连接
            connection = (HttpURLConnection) url.openConnection();

            // 设置请求方法
            connection.setRequestMethod("POST");

            // 设置请求属性，例如Content-Type
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

            // 发送请求参数
            String params = "account=" + account + "&password=" + password;
            connection.setDoOutput(true);
            connection.getOutputStream().write(params.getBytes());
            // 连接
            connection.connect();
            // 获取所有响应头
            Map<String, List<String>> headers = connection.getHeaderFields();
            for (String headerName : headers.keySet())
            {
                if (Objects.equals(headerName, "Location"))
                {
                    try
                    {
                        String o = headers.get(headerName).get(0);
                        sid = "sid=" + o.split("sid=")[1];
                        break;
                    } catch (Exception ignored)
                    {

                    }
                }
            }
        } catch (Exception ignored)
        {

        } finally
        {
            if (connection != null)
            {
                connection.disconnect();
            }
        }
        return sid;
    }

}